package ace.module.sms.core.impl.manager.impl;

import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.AbstractSpringDtoManager;
import ace.cmp.i18n.api.MessageSourceAssertService;
import ace.cmp.spring.data.jdbc.querydsl.core.util.DeleteFlagUtils;
import ace.module.sms.api.model.dto.SmsSupplierDto;
import ace.module.sms.core.impl.dao.entity.SmsSupplier;
import ace.module.sms.core.impl.manager.SmsSupplierManager;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 短信供应商 spring data jdbc querydsl rsql manager implement.
 *
 * @author Caspar
 */
@Slf4j
@AllArgsConstructor
@Component
public class SmsSupplierManagerImpl
    extends AbstractSpringDtoManager<SmsSupplier, Long, SmsSupplierDto>
    implements SmsSupplierManager {

  private final MessageSourceAssertService assertService;

  @Override
  public SmsSupplier getAndCheckAllById(Long id) {
    SmsSupplier smsSupplier = this.getById(id);

    assertService.isNull(
        smsSupplier, SmsSupplier.class.getName() + ".error-not-null", "短信渠道配置不能为空");

    assertService.isTrue(
        DeleteFlagUtils.isDelete(smsSupplier),
        SmsSupplier.class.getName() + ".error-not-null",
        "短信渠道配置不能为空");

    return smsSupplier;
  }
}
